
import { Notify } from 'vant';
//获取 axios
import axios from "axios";
//实例化axios对象
var service =axios.create({
    timeout: 3000,
    baseURL:'',
})

//设置拦截器
service.interceptors.request.use(
    (config)=>{
//    console.log('service.interceptors.request');
   config.headers['Authorization']='Bearer' + ' ' +localStorage.getItem('token')
   return config
    },(error)=>{
    return Promise.reject(error)
    }
)
//响应拦截器
service.interceptors.response.use(
    (res)=>{
        return res;
    },
    (error)=>{
        if (error.response.status == 401) {
           localStorage.removeItem('token')
            Notify('登陆过期，请重新登陆');
            alert('登陆过期，请重新登陆')
            this.$router.push('/landing')
        }
        else if (error.response.status == 404) {
            Notify('访问数据有误');
            
            alert('访问数据有误！')
        }
        else if (error.response.status == 500) {
            Notify('服务器内部错误！');
            alert('服务器内部错误！')
        }
        return Promise.reject(error)
    }
)
export default service;